package com.zhonghui.procurement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhonghui.common.annotation.Log;
import com.zhonghui.common.core.controller.BaseController;
import com.zhonghui.common.core.domain.AjaxResult;
import com.zhonghui.common.enums.BusinessType;
import com.zhonghui.procurement.domain.Assessment;
import com.zhonghui.procurement.service.IAssessmentService;
import com.zhonghui.common.utils.poi.ExcelUtil;
import com.zhonghui.common.core.page.TableDataInfo;

/**
 * 我的测评Controller
 *
 * @author zhonghui
 * @date 2023-12-10
 */
@RestController
@RequestMapping("/procurement/assessment")
public class AssessmentController extends BaseController
{
    @Autowired
    private IAssessmentService assessmentService;


    /**
     * 查询我的测评列表
     */
    @PreAuthorize("@ss.hasPermi('procurement:assessment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Assessment assessment)
    {
        startPage();
        List<Assessment> list = assessmentService.selectAssessmentList(assessment);
        return getDataTable(list);
    }

    /**
     * 导出我的测评列表
     */
    @PreAuthorize("@ss.hasPermi('procurement:assessment:export')")
    @Log(title = "我的测评", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Assessment assessment)
    {
        List<Assessment> list = assessmentService.selectAssessmentList(assessment);
        ExcelUtil<Assessment> util = new ExcelUtil<Assessment>(Assessment.class);
        util.exportExcel(response, list, "我的测评数据");
    }

    /**
     * 获取我的测评详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurement:assessment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assessmentService.selectAssessmentById(id));
    }

    /**
     * 新增我的测评
     */
    @PreAuthorize("@ss.hasPermi('procurement:assessment:add')")
    @Log(title = "我的测评", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Assessment assessment)
    {
        return toAjax(assessmentService.insertAssessment(assessment));
    }

    /**
     * 修改我的测评
     */
    @PreAuthorize("@ss.hasPermi('procurement:assessment:edit')")
    @Log(title = "我的测评", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Assessment assessment)
    {
        return toAjax(assessmentService.updateAssessment(assessment));
    }

    /**
     * 删除我的测评
     */
    @PreAuthorize("@ss.hasPermi('procurement:assessment:remove')")
    @Log(title = "我的测评", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assessmentService.deleteAssessmentByIds(ids));
    }

    /**
     * 获取测评任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('evaluation:task:query')")
    @GetMapping(value = "EvaluationTaskInfo/{id}")
    public AjaxResult getEvaluationTaskInfo(@PathVariable("id") Long id)
    {
        return success(assessmentService.selectEvaluationTaskById(id));
    }
}
